home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Mud 4.0 / port.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-30  |  1.2 KB  |  60 lines  |  [TEXT/MPS ]

  1. #ifndef mac
  2. #include <sys/types.h>
  3. #include <sys/time.h>
  4. #else
  5. #include <types.h>
  6. #include <time.h>
  7. #include <mac.h>
  8. #endif
  9.  
  10. #include "lint.h"
  11.  
  12. #ifdef sun
  13. time_t time PROT((time_t *));
  14. #endif
  15.  
  16.  
  17. /*
  18.  * This file defines things that may have to be changem when porting
  19.  * LPmud to new environments. Hopefully, there are #ifdef's that will take
  20.  * care of everything.
  21.  */
  22.  
  23. /*
  24.  * Return a random number in the range 0 .. n-1
  25.  */
  26. int random_number(n)
  27.     int n;
  28. {
  29. #ifdef RANDOM
  30.     return random() % n;
  31. #else /* RANDOM */
  32. #ifdef DRAND48
  33.     return (int)(drand48() * n);
  34. #else /* DRAND48 */
  35.     extern int current_time;
  36.  
  37.     return current_time % n;    /* Suit yourself :-) */
  38. #endif /* DRAND48 */
  39. #endif /* RANDOM */
  40. }
  41.  
  42. /*
  43.  * The function time() can't really be trusted to return an integer.
  44.  * But this game uses the 'current_time', which is an integer number
  45.  * of seconds. To make this more portable, the following functions
  46.  * should be defined in such a way as to retrun the number of seconds since
  47.  * some chosen year. The old behaviour of time(), is to return the number
  48.  * of seconds since 1970.
  49.  */
  50.  
  51. int get_current_time() {
  52.     return (int)time(0l);    /* Just use the old time() for now */
  53. }
  54.  
  55. char *time_string(t)
  56.     int t;
  57. {
  58.     return ctime((time_t *)&t);
  59. }
  60.